<template>
  <div class="bg">
    <nav-com
      title="公告列表"
      :showView='true'
      @back="backHandler()"
    ></nav-com>
    <div v-if="dataList.length==0" class="noData">--暂无公告--</div>
    <div class="notice">
      <div
        class="notice-list"
        v-for="item in dataList"
        :key="item"
        @click="toDetail(item.id)"
      >
        <div class="left">
          <van-badge
            dot
            v-if='!item.look'
          >
            <div class="img">
              <img
                :src="item.main_img || ''"
                style='width: 8vw; height: 8vw; border-radius: 5px;'
              >
            </div>
          </van-badge>
          <div
            class="img"
            v-else
          >
            <img
              :src="item.main_img || ''"
              style='width: 8vw; height: 8vw; border-radius:5px;'
            >
          </div>
          <div class="center-info">
            <div class="name">{{item.title}}</div>
            <div class="info">{{item.introduce}}</div>
          </div>
        </div>

        <div class="time">
          {{item.createtime.split(' ')[0]}}
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import navCom from "@/component/nav";
import { getNoticeList } from "@/api/api";
export default {
  components: {
    navCom,
  },
  data() {
    return {
      dataList: [],
    };
  },
  created() {
    this.initData();
  },
  methods: {
    //返回
    backHandler() {
       if(weixin.isAndroid()){
        window.JS_TROOPS.goBack()
      }else{
        this.$router.go(-1);
      }
    },
    initData() {
      getNoticeList()
        .then((result) => {
          if (result.data.code == 1) {
            this.dataList = result.data.data;
            // console.log(this.dataList.length);
          }
        })
        .catch((err) => {});
    },
    toDetail(id) {
      this.$router.push({
        name: "noticeDetail",
        params: {
          id,
        },
      });
    },
  },
};
</script>

<style scoped>
.noData{
  text-align: center;
  margin: 10vh 0;
}
.notice {
  background: #fff;
  margin: 3vw 0;

}
.notice-list {
  padding: 2vw 5vw;
  display: flex;
  align-items: center;
  margin-bottom: 3vw;
  padding-bottom: 3vw;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
}
.notice-list .img {
  background: #eee;
  width: 8vw;
  height: 8vw;
  border-radius: 0.7vw;
}
.notice-list .left {
  display: flex;
  align-items: center;
}
.notice-list .left .center-info {
  margin-left: 3vw;
  width: 50vw;
}
.notice-list .left .center-info .name {
  font-size: 16px;
  margin: 3px 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.notice-list .left .center-info .info {
  font-size: 14px;
  color: #999999;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.notice-list .time {
  font-size: 14px;
  float: right;
}
.bg {
  background: #f1f3f6;
  min-height: 100vh;
}
</style>
